package cn.cihon.ubi.qorosauto.storm;

import java.util.Map;

import cn.cihon.ubi.qorosauto.bo.TripData;
import cn.cihon.ubi.qorosauto.dao.file.TripDataDao;

import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichBolt;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;

public class TripDataStorageBolt extends BaseRichBolt{
	/*
	 * 本类主要对计算后的数据进行存储
	 */
	private static final long serialVersionUID = 1L;
	private OutputCollector collerctor;
	private TripDataDao tripDataDao = null;
	private TripData tripData = null;
	@Override
	public void prepare(Map stormConf, TopologyContext context,
			OutputCollector collector) {
		// TODO Auto-generated method stub
		this.collerctor = collector;
		this.tripDataDao = new TripDataDao();
		this.tripData = new TripData();
	}

	@Override
	public void execute(Tuple input) {
		// TODO Auto-generated method stub
		tripData = (TripData) input.getValue(0);
		this.tripDataDao.storeTofile(tripData);
		this.collerctor.ack(input);
	}

	@Override
	public void declareOutputFields(OutputFieldsDeclarer declarer) {
		// TODO Auto-generated method stub
		declarer.declare(new Fields("tripdatadao")); // 声明streamId
	}

}
